package cn.tedu.ems.controller;

import cn.tedu.ems.mapper.StudentMapper;
import cn.tedu.ems.pojo.dto.StudentDTO;
import cn.tedu.ems.pojo.dto.StudentUpdateDTO;
import cn.tedu.ems.pojo.entity.Student;
import cn.tedu.ems.pojo.vo.StudentUpdateVO;
import cn.tedu.ems.pojo.vo.StudentVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class StudentController {
    @Autowired(required = false)
    StudentMapper mapper;

    @RequestMapping("/student/select")
    public List<StudentVO> select(){
        return mapper.select();
    }

    @RequestMapping("/student/insert")
    public void insert(@RequestBody StudentDTO student){
        System.out.println("student = " + student);
        Student s = new Student();
        BeanUtils.copyProperties(student,s);
        s.setCourseId(1);
        s.setTeacherId(2);
        mapper.insert(s);
    }

    @RequestMapping("/student/delete")
    public void delete(int id){
        mapper.deleteById(id);
    }
    @RequestMapping("/student/update")
    public void update(@RequestBody StudentUpdateDTO student){
        System.out.println("student = " + student);
         mapper.update(student);
    }
    @RequestMapping("/student/update/selectById")
    public StudentUpdateVO selectByIdUpdate(int id){
        return mapper.selectByIdUpdate(id);
    }
    @RequestMapping("/student/selectDetail")
    public StudentVO selectDetail(String name, String getId){
        System.out.println("name = " + name + ", getId = " + getId);
        return mapper.selectDetail(name,getId);
    }

}
